#include "stdio.h"

typedef struct {
    int val;
    struct TreeNode *left;
    struct TreeNode *right;
} TreeNode;

void dfs_1302( TreeNode *node, int level, int *maxLevel, int *sum) {
    if (node == NULL) {
        return;
    }
    if (level > *maxLevel) {
        *maxLevel = level;
        *sum = node->val;
    } else if (level == *maxLevel) {
        *sum += node->val;
    }
    dfs_1302(node->left, level + 1, maxLevel, sum);
    dfs_1302(node->right, level + 1, maxLevel, sum);
}

int deepestLeavesSum(TreeNode *root) {
    int maxLevel = -1;
    int sum = 0;
    dfs_1302(root, 0, &maxLevel, &sum);
    return sum;
}

int main() {
    TreeNode *root = (TreeNode *) malloc(sizeof(TreeNode));
    root->val = 1;
    root->left = NULL;
    root->right = NULL;
    int v = deepestLeavesSum(root);
    printf("%d", v);


   char *c =  text_to_cstring("xxxxxxxxx");
    printf("%s", c);

}